﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="TravelTourism.GroupedItemsPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TravelTourism"
    xmlns:data="using:TravelTourism.Data"
    xmlns:common="using:TravelTourism.Common"
    xmlns:tiles="using:TravelTourism.VariableTemplate"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
	 <Page.TopAppBar>
        <AppBar x:Name="appBar2" Padding="10,0,10,0" BorderBrush="{x:Null}" MinHeight="88" Background="#FF7F4829" d:IsHidden="True">
            <Grid Margin="0" >
                <StackPanel Margin="110,10,0,10" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                	<Button x:Name="AppTop1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource TopApp}">
                		<Image Height="79" Width="64" Source="Assets/AppTop1.png" Stretch="Fill"/>
                	</Button>
                	<Button x:Name="AppTop2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource TopApp}">
                		<Image Height="79" Width="64" Source="Assets/AppTop2.png" Stretch="Fill"/>
                	</Button>
                	<Button x:Name="AppTop3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource TopApp}">
                		<Image Height="79" Width="64" Source="Assets/AppTop3.png" Stretch="Fill"/>
                	</Button>
                	<Button x:Name="AppTop4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource TopApp}">
                		<Image Height="79" Width="64" Source="Assets/AppTop4.png" Stretch="Fill"/>
                	</Button>
                   
                   
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.TopAppBar>
    <Page.Resources>

        <!--
            Collection of grouped items displayed by this page, bound to a subset
            of the complete item list because items in groups cannot be virtualized
        -->
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="TopItems"
            d:Source="{Binding AllGroups, Source={d:DesignInstance Type=data:SampleDataSource, IsDesignTimeCreatable=True}}"/>
      

        <tiles:VariableTiles x:Key="MyTemplateSelectorObj" 
                             
                             BookingTemplate="{StaticResource BookingItemTemplate}"
                             OffersTemplate="{StaticResource OffersItemTemplate}"
                             LocationBigTemplate="{StaticResource LocationBigItemTemplate}"
                             LocationSmallTemplate="{StaticResource LocationSmallItemTemplate}"
                             LocationBigTwoItemTemplate="{StaticResource LocationBigTwoItemTemplate}">
        </tiles:VariableTiles>
        
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
    	<Grid.Background>
    		<ImageBrush ImageSource="Assets/bg.jpg" Stretch="UniformToFill"/>
    	</Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Horizontal scrolling grid used in most view states -->
        <!--<GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Grouped Items"
            Grid.RowSpan="2"
            Padding="116,137,40,46"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemView_ItemClick">

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>                        
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,6">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                    Click="Header_Click"
                                    Style="{StaticResource TextPrimaryButtonStyle}" >
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>-->

        <tiles:VariableTileControl Grid.Row="1"
        	x:Name="itemGridView"
        	AutomationProperties.AutomationId="ItemGridView"
        	AutomationProperties.Name="Grouped Items"
        	Margin="0"
        	Padding="120,0,40,20"
        	ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
        	ItemTemplateSelector="{StaticResource MyTemplateSelectorObj}"
        	SelectionMode="None"
        	IsItemClickEnabled="True"
        	ItemClick="ItemView_ItemClick" HorizontalContentAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Auto">

            <tiles:VariableTileControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </tiles:VariableTileControl.ItemsPanel>
            <tiles:VariableTileControl.GroupStyle>
                <GroupStyle >
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <StackPanel Margin="1,0,0,6" Orientation="Horizontal">
                                <Button
        							AutomationProperties.Name="Group Title"
        							Content="{Binding Title}"
        							Click="Header_Click"
        							Style="{StaticResource TextButtonStyle}" FontWeight="Light" Foreground="white" FontSize="26.667" Background="#FFD71921"/>
                                <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="10,-4,0,10" Style="{StaticResource GroupHeaderTextStyle}" Foreground="White"/>

                            </StackPanel>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid ItemHeight="5" ItemWidth="5" MaximumRowsOrColumns="110" Orientation="Vertical" Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </tiles:VariableTileControl.GroupStyle>
        </tiles:VariableTileControl>

        <!-- Vertical scrolling list only used when snapped -->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemListView"
            AutomationProperties.Name="Grouped Items"
            Grid.Row="1"
            Visibility="Collapsed"
            Margin="0,-10,0,0"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
            ItemTemplate="{StaticResource Standard80ItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True"
            ItemClick="ItemView_ItemClick">

            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="7,7,0,0">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                    Click="Header_Click"
                                    Style="{StaticResource TextPrimaryButtonStyle}">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>

                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid x:Name="grid" HorizontalAlignment="Right" Height="100" Grid.Column="1" VerticalAlignment="Center" Width="234" Margin="-8,0,0,0">
                <Image Source="Assets/MainLogo.png" VerticalAlignment="Center"/>
            </Grid>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Text="Your app slogan goes here" Grid.Column="1" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}" Visibility="Visible"/>
            
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape">
                	<Storyboard>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="pageTitle">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Thickness>0,0,30,40</Thickness>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="grid">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Thickness>-8,0,0,0</Thickness>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                	</Storyboard>
                </VisualState>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="grid" Storyboard.TargetProperty="HorizontalAlignment">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Left"/>
                        </ObjectAnimationUsingKeyFrames>


                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0">
                            	<DiscreteObjectKeyFrame.Value>
                            		<Thickness>96,0,10,56</Thickness>
                            	</DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="grid" Storyboard.TargetProperty="HorizontalAlignment">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Left"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="grid" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="30,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="appBar2">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="backButton">
                        	<DiscreteObjectKeyFrame KeyTime="0">
                        		<DiscreteObjectKeyFrame.Value>
                        			<Visibility>Collapsed</Visibility>
                        		</DiscreteObjectKeyFrame.Value>
                        	</DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
